﻿package com.devilcat.dt{
	import com.devilcat.ws.Loginws;
	import com.devilcat.dt.Pokemondt;
	import com.devilcat.dt.Itemdt;
	import com.devilcat.dt.Gamedt;
	public class Playerdt {
		public var uid:Number=0;
		public var username:String="";
		public var token:Number=0;
		public var gold:Number=0;
		public var status:Number=0;
		public var leadpkm:Number=0;
		public var map:String="";
		public var miles:Number=0;
		public var pvpans:Number=0;
		public var pvpask:Number=0;
		public var uflag:String="1";
		public var pokemonList:Array;
		public var itemList:Array;
		public var eventList:Object;
		public function Playerdt(){
		}
		public function setHPLead(){			
			if(Gamedt.Player.pokemonList[0].CurrentHP<=0){
				var tempkm:Pokemondt;
				for(var i:int=0;i<Gamedt.Player.pokemonList.length;i++){
					if(Gamedt.Player.pokemonList[i].CurrentHP >0){
						tempkm=Gamedt.Player.pokemonList[i];
						Gamedt.Player.pokemonList[i]=Gamedt.Player.pokemonList[0];
						Gamedt.Player.pokemonList[0]=tempkm;
						Gamedt.updatePlayer.Update("leadpkm",Gamedt.Player.pokemonList[0].upid);
						break;
					}
				}
			}
		}
		public function setData(dt:Object){
			uid=dt.uid
			username=dt.username;
			//token=dt.token;
			//trace("setData "+dt.token);
			miles=dt.miles;
			gold=dt.gold;
			leadpkm=dt.leadpkm;
			map=dt.map;
			pvpans=dt.pvpans;
			pvpask=dt.pvpask;
			//uflag=dt.uflag;
		}
		public function AddItem(its:Itemdt){
			//trace(its.Code +" "+its.Name +" "+its.NumberOf);
			for(var i:int =0 ;i<itemList.length;i++){
				if(its.Code==itemList[i].Code){
					itemList[i].NumberOf+=its.NumberOf;
					Gamedt.updateItem.Update(itemList[i]);
					return;
				}
			}
			itemList.push(its);
			Gamedt.updateItem.Update(itemList[i],true);
		}
		public function checkEvent(el:String,en:Number):Boolean{
			if(el=="Fake")return true;
			if(en==0) return true;
			if(eventList[el]==en) return true;
			return false;
		}
		public function ChangeEvent(el:String,en:Number){
			trace("Update Event :"+el+", "+en);
			eventList[el]=en;
			Gamedt.updateEvent.Update(el,en+1);
		}
		public function getEventName(num:Number):String{
			switch(num){
				case 1: return "MainEvent";
				case 3: return "Celebi";
				default: return "FakeEvent";				
			}
		}
	}
}